package com.imax.center.controller;

import com.imax.center.common.Result;
import com.imax.center.model.amap.AddressComponentDTO;
import com.imax.center.service.AmapService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 高德地图控制器
 */
@Api(tags = "高德地图API")
@RestController
@RequestMapping("/api/amap")
public class AmapController {

    @Autowired
    private AmapService amapService;

    /**
     * 根据经纬度获取行政区划信息
     *
     * @param longitude 经度
     * @param latitude  纬度
     * @return 行政区划信息
     */
    @ApiOperation("根据经纬度获取行政区划信息")
    @GetMapping("/geocode")
    public Result<AddressComponentDTO> getAddressByLocation(
            @ApiParam(value = "经度", required = true) @RequestParam String longitude,
            @ApiParam(value = "纬度", required = true) @RequestParam String latitude) {
        return amapService.getAddressByLocation(longitude, latitude);
    }

    @ApiOperation("根据地址获取经纬度")
    @GetMapping("/getLonAndLatByAddress")
    public Result<Object> getLonAndLatByAddress(String address, String city) {
        return amapService.getLonAndLatByAddress(address, city);
    }

} 